
Page({
  data: {
    toView: 'red',
    scrollTop: 100,
    arrDate:[],
    bgFlag:0,
    timeArr:["00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"],
    gridFlag:0,
    selDate:'',
    selTime:''
  },
  upper: function (e) {
    console.log(e)
  },
  lower: function (e) {
    console.log(e)
  },
  scroll: function (e) {
    console.log(e)
  },
  tap: function (e) {

  },
  tapMove: function (e) {
    console.log("123")
    this.setData({
      scrollTop: this.data.scrollTop + 10
    })
  },
  onShow:function(){
    // wx.setNavigationBarTitle({
    //   title: '选择预约时间'
    // })
  },
  getStrDate:function(day){
    var date = new Date();
    date.setDate(date.getDate() + day);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate()

    var data = {
      str_date1: m + "月" + d+"日",
      str_date2: y + "-" + m + "-" + d
    }

    return data;
  },
  transToWeek: function (weekvalue){
    var week;
    var weekValue;
    weekValue = new Date(weekvalue.replace(/-/g, '/')).getDay()
    switch (weekValue) {
      case 1:
        week = "周一";
        break;
      case 2:
        week = "周二";
        break;
      case 3:
        week = "周三";
        break;
      case 4:
        week = "周四";
        break;
      case 5:
        week = "周五";
        break;
      case 6:
        week = "周六";
        break;
      case 0:
        week = "周日";
        break;
    }
    return week;
  },
  getDateData: function () {
    var self = this;
    var arrDate=[]
    for (var i = 0; i < 30; i++) {
      if(i==0){
        var data = {
          "day": self.getStrDate(i).str_date1,
          "week": '今天',
          "fulldate": self.getStrDate(i).str_date2
        }
      }else if(i==1){
        var data = {
          "day": self.getStrDate(i).str_date1,
          "week": '明天',
          "fulldate": self.getStrDate(i).str_date2
        }
      } else if (i == 2) {
        var data = {
          "day": self.getStrDate(i).str_date1,
          "week": '后天',
          "fulldate": self.getStrDate(i).str_date2
        }
      }
      else{
        var data = {
          "day": self.getStrDate(i).str_date1,
          "week": self.transToWeek(self.getStrDate(i).str_date2),
          "fulldate": self.getStrDate(i).str_date2
        }
      }

      arrDate.push(data)
    }
    self.setData({
      arrDate:arrDate
    })
   console.log(JSON.stringify(self.data.arrDate))
  },
  onLoad:function(){
    var self=this;
    self.getDateData()
    self.setData({
      selDate: self.getStrDate(0).str_date1,
      selTime: self.data.timeArr[0]
    })
  },
  tapSlideItem:function(e){
    var self=this;

    self.setData({
      bgFlag: e.target.dataset.index,
      selDate: e.target.dataset.datedata
    })
   
  },
  tapGrid:function(e){
    var self=this;
    self.setData({
      gridFlag: e.target.dataset.index,
      selTime: e.target.dataset.time
    })
  },
  tabBtnCancle:function(){
    wx.navigateBack({
      
    })  
  },
  tabBtnSure:function(){
    var pages = getCurrentPages()
    var self=this;
 
      pages[0].setData({
        sDate: self.data.selDate,
        sTime: self.data.selTime,
        isTime:true
      })
     
    console.log(self.data.selDate+" "+self.data.selTime)
    wx.navigateBack({
      
    })  
  }
})